#import os
#import os.path
#import glob
import logging
import sys
import re
import fileinput
#from os.path import isdir, join
from forest.registry import register_tool

logger = logging.getLogger('forest.tools.files.replace')

@register_tool('files.replace')
def replace(fname, find, replace):
    fin = fileinput.input(fname, inplace=1)
    pattern = re.compile(find)

    for line in fin:
        line = pattern.sub(replace, line)
        sys.stdout.write(line)

    fin.close()
